package ThreadDemo1;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-10-09
 * Time: 21:21
 */
class Contor{
     public int count = 0;
}
public class ThreadDemo14 {
    public static void main(String[] args) {
        Contor contor = new Contor();
        //内存可见性，编译器优化，直接不改变里面的值
        Thread t1 = new Thread(()->{
           while(contor.count == 0){
               //如果 == 0 循环就一直执行下去 也可以添加一个线程休眠
               try {
                   Thread.sleep(100);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
            System.out.println("t1 线程循环结束!");
        });

        Thread t2 = new Thread(()->{
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个数字: ");
            contor.count = scanner.nextInt();
        });

        t1.start();
        t2.start();
    }
}
